package com.ruoyi.blog.controller;

import cn.hutool.cache.Cache;
import cn.hutool.cache.CacheUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.cms.domain.Article;
import com.ruoyi.cms.service.AdultService;
import com.ruoyi.cms.service.IArticleService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.utils.R;
import com.ruoyi.easywenku.entity.Question;
import com.ruoyi.easywenku.entity.RegistrationInfo;
import com.ruoyi.easywenku.service.IQuestionService;
import com.ruoyi.easywenku.service.RegistrationInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/registrationInfo")
public class ApiRegistrationInfoController extends BaseController {
    private static final String prefix = "adultexam";

    @Autowired
    private AdultService adultService;

    @Autowired
    RegistrationInfoService registrationInfoService;

    /**
     * @return
     */
    @GetMapping({""})
    public String index(Model model) {
        List<Article> applicationCheats = (List<Article>) AdultExamController.blogCache.get("applicationCheats");
        if(applicationCheats==null){
            applicationCheats=adultService.ArticleByCategPage("70", 1, 7);
            applicationCheats.addAll(adultService.ArticleByCategPage("71", 1, 7));
            applicationCheats.addAll(adultService.ArticleByCategPage("72", 1, 7));
            applicationCheats.addAll(adultService.ArticleByCategPage("73", 1, 7));
            applicationCheats.addAll(adultService.ArticleByCategPage("74", 1, 7));
            applicationCheats.addAll(adultService.ArticleByCategPage("75", 1, 7));
            AdultExamController.blogCache.put("applicationCheats",applicationCheats);
        }

        List<Article> latestTestQuestions = (List<Article>) AdultExamController.blogCache.get("latestTestQuestions");
        if(latestTestQuestions==null){
            latestTestQuestions = adultService.ArticleByCategPage("44", 1, 7);
            latestTestQuestions.addAll(adultService.ArticleByCategPage("49", 1, 7));
            latestTestQuestions.addAll(adultService.ArticleByCategPage("53", 1, 7));
            latestTestQuestions.addAll(adultService.ArticleByCategPage("58", 1, 7));
            latestTestQuestions.addAll(adultService.ArticleByCategPage("62", 1, 7));
            latestTestQuestions.addAll(adultService.ArticleByCategPage("66", 1, 7));
            AdultExamController.blogCache.put("latestTestQuestions",latestTestQuestions);
        }

        model.addAttribute("latestTestQuestions", latestTestQuestions);
        model.addAttribute("applicationCheats", applicationCheats);
        model.addAttribute("blockType","registrationInfo");
     return prefix+ "/saveStudentDetails";
    }
    /**
     * save
     *
     * @param RegistrationInfo 报名信息
     * @return
     */
    @PostMapping({"/save"})
    @ResponseBody
    public R index(@RequestAttribute("userId") Long userId, RegistrationInfo RegistrationInfo) {
        RegistrationInfo.setUserId(userId);
        registrationInfoService.save(RegistrationInfo);
        return R.ok();
    }
}
